package com.hdf.etdemo.viewframe;

import com.hdf.easytools.base.EasyToolsActivity;
import com.hdf.etdemo.R;

import com.hdf.etdemo.viewframe.adapter.FragmentAdapter;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class ViewPageFragmentActivity extends EasyToolsActivity {
	public static final int TAB_page1 = 0;
	public static final int TAB_page2 = 1;
	public static final int TAB_page3 = 2;
	public static final int TAB_page4 = 3;
	
	private RadioButton radio1,radio2,radio3,radio4;
	private ViewPager viewPager;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_view_page_fragment);
		setActionBarVib();
		viewPager = (ViewPager) findViewById(R.id.viewpager);
		radio1=(RadioButton) findViewById(R.id.radio_home);
		radio2=(RadioButton) findViewById(R.id.radio_account);
		radio3=(RadioButton) findViewById(R.id.radio_money);
		radio4=(RadioButton) findViewById(R.id.radio_more);
		radio1.setOnClickListener(this);
		radio2.setOnClickListener(this);
		radio3.setOnClickListener(this);
		radio4.setOnClickListener(this);
		FragmentAdapter adapter = new FragmentAdapter(
				getSupportFragmentManager());
		viewPager.setAdapter(adapter);
		addListener();
	}

	
	private void addListener() {
		viewPager.setOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int id) {
				switch (id) {
				case TAB_page1:
					radio1.setChecked(true);
					break;
				case TAB_page2:
					radio2.setChecked(true);
					break;
				case TAB_page3:
					radio3.setChecked(true);
					break;
				case TAB_page4:
					radio4.setChecked(true);
					break;
				default:
					break;
				}
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {

			}

			@Override
			public void onPageScrollStateChanged(int arg0) {

			}
		});
	}
	

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.radio_home:
			viewPager.setCurrentItem(TAB_page1);
			break;
		case R.id.radio_account:
			viewPager.setCurrentItem(TAB_page2);
			break;
		case R.id.radio_money:
			viewPager.setCurrentItem(TAB_page3);
			break;
		case R.id.radio_more:
			viewPager.setCurrentItem(TAB_page4);
			break;
		default:
			break;
		}	
	}

}
